﻿using System;
using System.ServiceModel.Channels;

namespace Framework.Remoting.Conventions
{
    public abstract class BindingFactory<T> : IBindingFactory<T>
        where T : Binding
    {
        
        public abstract T Create();

        

        protected T Setup(T binding)
        {
            binding.CloseTimeout = new TimeSpan(Int32.MaxValue);
            binding.OpenTimeout = new TimeSpan(Int32.MaxValue);
            binding.ReceiveTimeout = new TimeSpan(Int32.MaxValue);
            binding.SendTimeout = new TimeSpan(Int32.MaxValue);

            return binding;
        }
    }

    public class BindingFactory : IBindingFactory
    {
        public Binding Create(string bindingType)
        {
            if (bindingType == "netTcpBinding")
            {
                return new NetTcpBindingFactory().Create();
            }

            if (bindingType == "basicHttpBinding")
            {
                return new BasicHttpBindingFactory().Create();
            }

            throw new BindingNotFoundException(string.Format("Binding : {0} does not exist", bindingType));

        }
    }
}